from django.db import models
from django.db.models.signals import class_prepared
'''
This is a hack.
It intercepts the signals that make the User class and changes the max_length of username to 75
This goes with the customized registration app that has been modified to make the username = the email address

Tightly Coupled (sorry) with 
    ocms.registration.forms
    ocms.registration.backends.defaultt.__init__.register

See: http://stackoverflow.com/questions/2610088/can-djangos-auth-user-username-be-varchar75-how-could-that-be-done

'''
def longer_username(sender, *args, **kwargs):
    # You can't just do `if sender == django.contrib.auth.models.User`
    # because you would have to import the model
    # You have to test using __name__ and __module__
    if sender.__name__ == "User" and sender.__module__ == "django.contrib.auth.models":
        sender._meta.get_field("username").max_length = 75
        sender._meta.get_field("username").help_text = "Username is your email address"
        #sender._meta.get_field("email").unique = True

class_prepared.connect(longer_username)
